import React from "react";
import AnnexUploadField from "components/AnnexUploadField";

import { openNotificationWithIcon } from "../../../../../utils/comm";

class UploadConfig extends React.Component {
  constructor(props) {
    super(props);
    this.openNotificationWithIcon = openNotificationWithIcon.bind(this);
  }

  onChange = changedValue => {
    const { onBlur } = this.props;
    // const selectedItemParam = selectedItem.params.template || [];
    const newValue = (changedValue || [])
      .filter(f => {
        if (f.status !== "done") {
          return false;
        }
        const { response: { datas = "" } = {} } = f;
        return datas.length > 0;
      })
      .map(f => ({ ...f, fileName: f.name }));
    // const newParams = [ ...newValue];
    if (onBlur) onBlur("params", { template: newValue });
  };

  render() {
    const { className = "", selectedItem = {}, required = false } = this.props;
    const { params = {} } = selectedItem;

    return (
      <React.Fragment>
        <div className={className}>
          <div
            className={`item__lable ${required ? "item__lable_required" : ""}`}
          >
            附件模板：
          </div>

          <AnnexUploadField params={params || {}} onChange={this.onChange} />
        </div>
      </React.Fragment>
    );
  }
}

export default UploadConfig;
